﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using DataAccessLayer;

namespace BusinessLayer
{
    public class Catalogue
    {
        public string cat { get; set; }
        public string equip { get; set;}
        public string season_r { get; set;}
        public DateTime startD { get; set;}
        public DateTime endD { get; set;}
        public int  season { get; set;}
        

        public Catalogue()
        {
            cat = "";
            equip = "";
            season_r = "";
            startD = DateTime.MaxValue;
            endD = DateTime.MaxValue;
            season = 0;
        }

        public Catalogue(string ct,string eq,string sea_r, DateTime str_D, DateTime ed_D, int sea)
        {
            cat = ct;
            equip = eq;
            season_r = sea_r;
            startD = str_D;
            endD = ed_D;
            season = sea;
        }

        public void sav_catalogue()
        {
            DataAccessLayer.csDAL objdal = new DataAccessLayer.csDAL();
            List<csparameterListType> par = new List<csparameterListType>();

            par.Add(new csparameterListType("@EQUIPMENT_NUMBER", System.Data.SqlDbType.VarChar, equip));
            par.Add(new csparameterListType("@SEASON", System.Data.SqlDbType.VarChar, season_r));
            par.Add(new csparameterListType("@STARTDATE", System.Data.SqlDbType.Date, startD));
            par.Add(new csparameterListType("@ENDDATE", System.Data.SqlDbType.Date, endD));
            par.Add(new csparameterListType("@SEASON", System.Data.SqlDbType.Int, season));

            objdal.executespreturndr("SAV_CATA", par);
        }

        public List<Catalogue > get_Catal()
        {
            List<csparameterListType> par = new List<csparameterListType>();
            List<Catalogue > objlst = new List<Catalogue >();
            DataAccessLayer.csDAL objdal = new DataAccessLayer.csDAL();
            IDataReader datareader = null;

            datareader = objdal.executespreturndr("GET_CATA");
            while (datareader.Read())
            {
                Catalogue objC = new Catalogue ();
                populate_reader(datareader, objC);
                objlst.Add(objC);
            }
            return objlst;
        }

        private void populate_reader(IDataReader datareader, Catalogue  objC)
        {
            objC.cat = datareader.GetString(0);
            objC.equip = datareader.GetString(1);
            objC.season_r  = datareader.GetString(2);
            objC.startD = datareader.GetDateTime(3);
            objC.endD = datareader.GetDateTime(4);
            objC.season = datareader.GetInt16(5);
        }

        public void update_catal()
        {
            DataAccessLayer.csDAL objdal = new DataAccessLayer.csDAL();
            List<csparameterListType> par = new List<csparameterListType>();

            par.Add(new csparameterListType("@EQUIPMENT_NUMBER", System.Data.SqlDbType.VarChar, equip));
            par.Add(new csparameterListType("@SEASON", System.Data.SqlDbType.VarChar, season_r));
            par.Add(new csparameterListType("@STARTDATE", System.Data.SqlDbType.Date, startD));
            par.Add(new csparameterListType("@ENDDATE", System.Data.SqlDbType.Date, endD));
            par.Add(new csparameterListType("@SEASON", System.Data.SqlDbType.Int, season));
           
            objdal.executespreturnnd("UPDATE_CATA", par);
        }


    }
}